Skip to content

fix: noexcept for Observer#4039

Merged
dbarker merged 2 commits intoopen-telemetry:mainfrom
proost:fix-avoid-exception-observerresult
May 2, 2026
Merged

fix: noexcept for Observer#4039
dbarker merged 2 commits intoopen-telemetry:mainfrom
proost:fix-avoid-exception-observerresult

Conversation

@proost
Copy link
Copy Markdown
Contributor

@proost proost commented Apr 30, 2026

Fixes #2053

Changes

bad allocation, bad variant access can happen. First i try to logging when exception happens, But following the comment, ignore it.

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

@proost proost requested a review from a team as a code owner April 30, 2026 08:57
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.05%. Comparing base (d2be704) to head (2535646).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...nclude/opentelemetry/sdk/metrics/observer_result.h 0.00% 4 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4039      +/-   ##
==========================================
- Coverage   82.07%   82.05%   -0.02%     
==========================================
  Files         385      385              
  Lines       15891    15895       +4     
==========================================
  Hits        13041    13041              
- Misses       2850     2854       +4     
Files with missing lines Coverage Δ
...nclude/opentelemetry/sdk/metrics/observer_result.h 71.43% <0.00%> (-28.57%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lalitb
Copy link
Copy Markdown
Member

lalitb commented May 1, 2026

Non-blocking: this improves the map-insertion failure path, but I think attributed observations can still terminate before this catch runs. The MetricAttributes construction copies attributes through noexcept callbacks/helpers that can allocate while storing keys/values. If that allocation throws, terminate happens before the outer catch in Observe() can handle it. We should either remove/catch those lower-level noexcept paths here or track it as a follow-up.

Copy link
Copy Markdown
Member

@lalitb lalitb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks.

Copy link
Copy Markdown
Member

@dbarker dbarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

Still an open question about how to provide user visibility of these errors during development. Okay to silently return for now.

@dbarker dbarker merged commit 0668d64 into open-telemetry:main May 2, 2026
122 of 127 checks passed
@proost proost deleted the fix-avoid-exception-observerresult branch May 2, 2026 23:01
@malkia
Copy link
Copy Markdown

malkia commented May 3, 2026

Wait - why are we doing POKEMON coding here? If there is an actual memory stomp, it'll obscure it even more. This is dangerous!

@lalitb
Copy link
Copy Markdown
Member

lalitb commented May 3, 2026

Wait - why are we doing POKEMON coding here? If there is an actual memory stomp, it'll obscure it even more. This is dangerous!

Fair point. This was approved and merged because it avoids std::terminate from the noexcept metrics path, but I agree the current catch (...) + silent return is too broad. I think we should improve this with a narrower follow-up fix.

@proost
Copy link
Copy Markdown
Contributor Author

proost commented May 3, 2026

Wait - why are we doing POKEMON coding here? If there is an actual memory stomp, it'll obscure it even more. This is dangerous!

Valid concern. As dbaker mentioned, I think the broader issue is how to make these failures observable without putting the application at risk.

If narrowing the catch clauses is needed here, I can send a follow-up fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code health] clang-tidy cleanup

4 participants